SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the Activity table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Activity_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Ip nvarchar (50)  = null ,

	@DateLogin datetime   = null ,

	@DateLogout datetime   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Ip]
	, [DateLogin]
	, [DateLogout]
    FROM
	[dbo].[Activity]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Ip] = @Ip OR @Ip IS NULL)
	AND ([DateLogin] = @DateLogin OR @DateLogin IS NULL)
	AND ([DateLogout] = @DateLogout OR @DateLogout IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Ip]
	, [DateLogin]
	, [DateLogout]
    FROM
	[dbo].[Activity]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Ip] = @Ip AND @Ip is not null)
	OR ([DateLogin] = @DateLogin AND @DateLogin is not null)
	OR ([DateLogout] = @DateLogout AND @DateLogout is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
